<?php

namespace admin\controllers;

use admin\components\BaseAuthController;
use app\models\Withdraw;

class WithdrawController extends BaseAuthController {

    public $name = '提现管理';

    public function actionIndex($status = Withdraw::STATUS_PENDING) {
        $model = new Withdraw();
        $dataProvider = $model->search(['status' => $status]);
        return $this->render(compact('dataProvider'));
    }

    public function actionSuccess($id) {
        $model = Withdraw::findOne($id);
        if (!$model || !$model->getIsPending()) {
            return $this->error();
        }
        $model->setScenario('success');
        if (!$model->load($this->post())) {
            return $this->render(compact('model'), 'save');
        }
        return $model->success();
    }

    public function actionReject($id) {
        $model = Withdraw::findOne($id);
        if (!$model || !$model->getIsPending()) {
            return $this->error();
        }
        $model->setScenario('reject');

        if (!$model->load($this->post())) {
            return $this->render(compact('model'), 'save');
        }
        return $model->reject();
    }
}
